<%@ page language="java" import="java.util.*,java.sql.*"
	pageEncoding="UTF-8"%>
<%@page import="com.message.dao.ConnectionPool"%>

<%@include file="util.jsp"%> 
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	request.setCharacterEncoding("utf-8");
	String name = request.getParameter("userName");
	String title = request.getParameter("title");
	String context = request.getParameter("context");
	if (name == null || title == null || context == null) {
		System.out.println("数据不完整");
		response.sendRedirect("index.jsp");
		return;
	}
	name = toHtml(name);
	title = toHtml(title);
	context = toHtml(context);
	String ip = request.getRemoteAddr();

	Connection conn = ConnectionPool.getConnection();

	String sql = "INSERT INTO guestmessage(title,userName,content,ip) values(?,?,?,?)";
	PreparedStatement pstm = conn.prepareStatement(sql);
	pstm.setString(1, title);
	pstm.setString(2, name);
	pstm.setString(3, context);
	pstm.setString(4, ip);
	if (pstm.executeUpdate()<=0) {
		System.out.println("发送出错了");
		return;
	}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>发送消息</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

	</head>

	<body>
		发送成功
		<a href="index.jsp">再发一条</a>
	</body>
</html>
